package com.ymatou.iapi.couponservice.service;

import java.util.ArrayList;

import org.json.JSONObject;

import com.ymatou.iapi.coupon.parameter.old.SellerCouponsList;
import com.ymatou.iapi.couponservice.parameter.CouponCodes;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
/**
*兑换优惠券all
*FreeMaker Template自动生成代码
*/
public class ConversionCouponCall extends YmatouBaseCall{
	private static String opurl ="api/Promotion/ConversionCoupon";
	
	public ConversionCouponCall() {
		super(EnvSetup.getSystemUrl("couponservice"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		return getString("statusCode");		
	}

	/**
	 * 获取Message
	 * 
	 * @return
	 */
	public String getMessage() {
		return getString("message");	
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public String getData() {
		return getString("data");	
	}

	public String getConversionSuccess() {
		String Code = null;
		try {
			Code = new JSONObject(getData()).getString("conversionSuccess");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}
	
	public String getConversionFailReason() {
		String Code = null;
		try {
			Code = new JSONObject(getData()).getString("conversionFailReason");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}
	
	 public ArrayList<String> getCouponCodes()
	    {
		 ArrayList<String> data = null;
	        try {
	            data =
	                    (ArrayList<String>) FormatUtil.GSONToObject(
	                    		 new JSONObject(getData()).getString("couponCodes"), ArrayList.class);

	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return data;
	    }
}